<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/MesquiteTemplate.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />


<!-- InstanceBeginEditable name="doctitle" -->
<title>Scripts &amp; Macros</title>
<!-- InstanceEndEditable -->

<![endif]--><!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.thrColFixHdr #sidebar2, .thrColFixHdr #sidebar1 { padding-top: 30px; }
.thrColFixHdr #mainContent { zoom: 1; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->

<style type="text/css">
<!--
-->
</style>
<link href="CSS/mesquitePackage.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css" />

<script src="SpryAssets/SpryCollapsiblePanel.js" type="text/javascript"></script>
<script type="text/javascript" src="SpryAssets/SpryURLUtils.js"></script>
<script type="text/javascript" src="javascript/mesquite.js"></script>

<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>

<body bgcolor="#ffffff" class="thrColFixHdr" >

<div id="container">
  <div id="header">
    <table width="100%" border="0" cellpadding="4">
  <tr>
    <td width="51%"><strong id="PackageTitle">Mesquite</strong></td>
    <td width="33%" align="right"><div id="subtitle"><!-- InstanceBeginEditable name="subtitle" -->Scripts &amp; Macros<!-- InstanceEndEditable --></div></td>
    <td width="2%">&nbsp;</td>
    <td width="14%">Version 3.81<br />
      April 2023<br /></td>
  </tr>
</table>

</div>
  
  
<div id="sidebar1">
  
  
  
  
  <div id="NonCollapsiblePanel">
    <a href="javascript:pageLink('http://www.mesquiteproject.org')">Mesquite Website Home</a>
  </div>
  <div id="NonCollapsiblePanel">
    <a href="javascript:pageLink('home.html')">Introduction</a>
  </div>
  <div id="NonCollapsiblePanel">
    <a href="javascript:pageLink('Installation.html')">Download & Installation</a>
  </div>
  <div id="NonCollapsiblePanel">
    <a href="javascript:pageLink('History%20of%20New%20Features.html')">Recent Changes</a>
  </div>

  <div id="OverviewOfMesquitePanel" class="CollapsiblePanel">
    <div class="CollapsiblePanelTab" tabindex="0">Overview of Mesquite ˇ</div>
    <div class="CollapsiblePanelContent" style="display: block">
  		<table width="100%" border="0" cellpadding="1">
  			<tr><td><a href="javascript:pageLink('What%20Mesquite%20does.html');">What Mesquite Does</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Mesquites%20Features.html');">List of Features</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Development%20Team.html');">Development Team</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Contact%20Us.html');">Contact Us</a></td></tr>
		</table>
    </div>
  </div>
  <div id="GettingStartedPanel" class="CollapsiblePanel">
    <div class="CollapsiblePanelTab" tabindex="0">Getting Started ˇ</div>
    <div class="CollapsiblePanelContent" style="display: block">
  		<table width="100%" border="0" cellpadding="1">
  			<tr><td><a href="javascript:pageLink('Installation.html');">Download and Installation</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Additional%20Mesquite%20Packages.html');">Additional Packages</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Beginning%20Mesquite.html');">Beginning Mesquite</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Example%20Files.html');">Example Files</a></td></tr>
		</table>
    </div>
  </div>
  <div id="BasicMesquiteOperationPanel" class="CollapsiblePanel">
    <div class="CollapsiblePanelTab" tabindex="0">Basic  Operations ˇ</div>
    <div class="CollapsiblePanelContent" style="display: block">
  		<table width="100%" border="0" cellpadding="1">
  			<tr><td><a href="javascript:pageLink('Files.html');">Files</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Menus.html');">Menus</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Windows.html');">Windows</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Charts.html');">Charts</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Selection.html');">Selection</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Modules.html');">Modules</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Simplifying%20the%20Interface.html');">Simplifying Mesquite</a></td></tr>
		</table>
    </div>
  </div>
  <div id="TaxaTreesCharactersPanel" class="CollapsiblePanel">
    <div class="CollapsiblePanelTab" tabindex="0">Taxa, Trees, Characters ˇ</div>
    <div class="CollapsiblePanelContent" style="display: block">
  		<table width="100%" border="0" cellpadding="1">
  			<tr><td><a href="javascript:pageLink('Characters%20&%20Matrices.html');">Characters &amp; Matrices</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Taxa.html');">Taxa</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Trees.html');">Trees</a></td></tr>
		</table>
    </div>
  </div>
  <div id="AnalysesPanel" class="CollapsiblePanel">
    <div class="CollapsiblePanelTab" tabindex="0">Analyses ˇ</div>
    <div class="CollapsiblePanelContent" style="display: block">
  		<table width="100%" border="0" cellpadding="1">
  			<tr><td><a href="javascript:pageLink('Character%20Evolution.html');">Character Evolution</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Align.html');">Sequence Alignment</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Analyzing%20Molecular%20Data.html');">Molecular Data</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Diversification.html');">Diversification</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Gene%20Trees.html');">Gene Trees</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Simulations%20&%20Randomizations.html');">Simulations &amp; Randomizations</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Analyzing%20Continuous%20Characters.html');">Continuous Characters</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Studies%20of%20Tree%20Topology.html');">Studies of Tree Topology</a></td></tr>
		</table>
    </div>
  </div>
  <div id="WorkflowsPanel" class="CollapsiblePanel">
    <div class="CollapsiblePanelTab" tabindex="0">Workflows ˇ</div>
    <div class="CollapsiblePanelContent" style="display: block">
  		<table width="100%" border="0" cellpadding="1">
  			<tr><td><a href="javascript:pageLink('Managing%20Molecular%20Data.html');">Managing Molecular Data</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Managing%20Continuous%20Data.html');">Managing Continuous Data</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Interactions%20with%20Other%20Programs.html');">Interactions with other programs</a></td></tr>
		</table>
    </div>
  </div>
  <div id="GettingHelpPanel" class="CollapsiblePanel">
    <div class="CollapsiblePanelTab" tabindex="0">Getting Help ˇ</div>
    <div class="CollapsiblePanelContent" style="display: block">
  		<table width="100%" border="0" cellpadding="1">
  			<tr><td><a href="javascript:pageLink('Learning%20how%20to%20use%20Mesquite.html');">Learning Mesquite</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Simplifying%20the%20Interface.html');">Simplifying Mesquite</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Bugs%20and%20Troubleshooting.html');">Bugs &amp; Troubleshooting</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Getting%20Help.html');">Getting Help</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Suggesting%20New%20Features.html');">Your Suggestions</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Glossary.html');">Glossary</a></td></tr>
  			<tr><td><a href="javascript:pageLink('FAQ.html');">FAQ</a></td></tr>
		</table>
    </div>
  </div>
  <div id="TechnicalDetailsPanel" class="CollapsiblePanel">
    <div class="CollapsiblePanelTab" tabindex="0">Technical Details ˇ</div>
    <div class="CollapsiblePanelContent" style="display: block">
  		<table width="100%" border="0" cellpadding="1">
  			<tr><td><a href="javascript:pageLink('How%20Mesquite%20Works.html');">How Mesquite Works</a></td></tr>
  			<tr><td><a href="javascript:pageLink('MesquiteLogSupport.html');">Log & Support Files</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Scripts%20&%20Macros.html');">Scripts &amp; Macros</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Source%20Code.html');">Source Code</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Developers%20Documentation.html');">Developer's Documentation</a></td></tr>
		</table>
    </div>
  </div>
  <div id="HistoryPanel" class="CollapsiblePanel">
    <div class="CollapsiblePanelTab" tabindex="0">History ˇ</div>
    <div class="CollapsiblePanelContent" style="display: block">
  		<table width="100%" border="0" cellpadding="1">
  			<tr><td><a href="javascript:pageLink('History%20of%20Mesquite.html');">History of Mesquite</a></td></tr>
  			<tr><td><a href="javascript:pageLink('whyMesquite.html');">Why Mesquite?</a></td></tr>
  			<tr><td><a href="javascript:pageLink('History%20of%20New%20Features.html');">New Features & Bug List</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Release%20Dates.html');">Release Dates</a></td></tr>
		</table>
    </div>
  </div>
  <div id="PublishingResultsPanel" class="CollapsiblePanel">
    <div class="CollapsiblePanelTab" tabindex="0">Publishing Results ˇ</div>
    <div class="CollapsiblePanelContent" style="display: block">
  		<table width="100%" border="0" cellpadding="1">
  			<tr><td><a href="javascript:pageLink('Documenting%20Your%20Work.html');">Documenting your work</a></td></tr>
  			<tr><td><a href="javascript:pageLink('How%20to%20Cite%20Mesquite.html');">Citing Mesquite</a></td></tr>
  			<tr><td><a href="javascript:pageLink('Publishing%20Results.html');">Publishing results</a></td></tr>
		</table>
    </div>
  </div>

  <div id="NonCollapsiblePanel">
    <a href="javascript:pageLink('Acknowledgements.html')">Acknowledgments</a>
  </div>

<h3>&nbsp;</h3>
  <!-- end #sidebar1 --></div>

  <div id="mainContent">
    
<!-- InstanceBeginEditable name="content" -->
    
    
<h1 id="toc0"><a name="Scripting and Macros"></a>Scripting and Macros</h1>
 Mesquite's scripting system allows modules and other objects to be scripted using text commands. Mesquite uses scripting by text commands as follows:<br />
<br />
<ul><li>When a menu item, button, or tool is used, Mesquite sends a text command to the appropriate object, informing it of the use. This means that most user interface commands can also be executed in scripts and macros.</li><li>When Mesquite re-reads a NEXUS file, it attempts to return windows and analyses to approximately the same condition as when the file had been saved. It does this by reading scripting instructions in a MESQUITE block that Mesquite had written into the file when saved. Thus, Mesquite writes scripts called &quot;Snapshots&quot; to later instruct itself.</li><li>Macros are script files which, if placed in the recognized directories, appear in submenus as selectable menu items. When selected, the macro is executed. Mesquite recognizes directories called &quot;macros&quot; within the Mesquite_Folder directory and the &quot;Mesquite_Prefs&quot; subdirectory of the Mesquite_Support_Files directory.</li><li>Not all scripts in MESQUITE blocks need to be written by Mesquite. Users can write MESQUITE block scripts by hand.</li><li>Users can send a script to a window using Window&gt;Scripting&gt;Send Script. This page gives some <a  href="Scripts%20%26%20Macros.html#examples">simple examples</a> for the tree window.</li></ul><br />
The text commands are sent to modules or other objects. The particular text commands to which a module or other object responds will depend on the object. When Mesquite shows a web page for the first time, it attempts to compile automatically documentation for scripting commands that is available. This includes commands predefined by the scripting language, and commands belonging to particular modules. This compiled documentation is available from the web page linked from the &quot;Scripting Commands&quot; menu item in the Help menu when Mesquite is running.<br />
Mesquite's scripting language is not as human-friendly as it might be at present, especially in its handling of variables and aspects such as the lack of &quot;else&quot; statements. Since the vast majority of Mesquite scripts won't be written by humans but by Mesquite itself, that is not such a liability as it might seem. We hope to reform the scripting language in the future.<br />
<br />
<h2 id="toc1"><a name="Scripting and Macros-Macros"></a><a name="macros"></a>Macros</h2>
 Scripts performing some special function can be written and distributed by programmers to end users as &quot;Macros&quot;. For some calculations or display functions, the number of different analyses a user might like to do are too many to be easily supported by a graphical user interface. For instance, the user might like to print the ancestral state reconstruction of a character using a series of different stepmatrices. One can invent many such scenarios in which something repetitious is needed, and a module would be hard-pressed to maintain each as an option. Thus, small scripts using Mesquite's scripting language can be written and placed in the &quot;macros&quot; folder. These macros will appear as options in an appropriate place, depending upon where they are applicable. When the user selects the menu item, the script is executed.<br />
Macros can also be automatically composed by Mesquite. As noted above, Mesquite composes a script to place in NEXUS files that it saves. This script applies only to the particular saved file. In some contexts, you can ask Mesquite to save a script as a macro file. This is currently available in only a few contexts. Save Window as Macro in the Analysis menu and Window menu save macros that attempt to reproduce the condition (including analyses) of the foremost window. This is useful to reproduce a complex chart with a different data file, for example. Save Macro For Tree Drawing in the Display menu of a Tree Window creates a macro by which you can later reproduce the current appearance of the tree drawing (background color, font, tree form, orientation, and so on). Save Tree Analysis As Macro in the Tree menu of a Tree window creates a macro by which to reproduce a particular analysis with the tree. Macros so created are stored in Mesquite_Support_Files/Mesquite_Prefs/macros, and could be (for instance) shared by users.<br />
<br />
<h2 id="toc2"><a name="Scripting and Macros-Learning about scripting"></a><a name="learning"></a>Learning about scripting</h2>
 Users can learn about the scripting language from this web page, but also by inspection of existing scripts. Some sources of scripts to examine are:<br />
<ul><li>The MESQUITE block within NEXUS files saved by Mesquite. If you want to know how to script a tree window to trace a character, for instance, open a tree window, turn on character tracing, and save the file. You can look at the file with a text editing program to see how such a script would be written</li><li>If there are any macros installed, you can examine the files that specify them. These files are simple text files with scripts. Macros would be found in folders called &quot;macros&quot; within the Mesquite_Folder directory, and in the macros folder of the &quot;Mesquite_Prefs&quot; directory of the Mesquite_Support_Files directory.</li><li>The menu item Window&gt;Scripting&gt;Show Snapshot shows a snapshot for the window — the script that would be needed to set the window to its current state.</li></ul>Another way to learn about the language and particular scripting commands is to look at the web pages linked from the &quot;Scripting Commands&quot; menu item in the Help menu when Mesquite is running. In particular, examine the page on universal commands, which shows basic commands available regardless of the object being scripted, including the basic flow control and variable-defining commands of the system. (We cannot provide a link here to this web page because this web page is created by Mesquite when it runs, and is placed in a location that depends on your particular computer. After running Mesquite once, you may want to find some of these files and save a bookmark/alias/shortcut to them — the file on basic scripting commands is named 'puppeteer.html').<br />
<h2 id="toc3"><a name="Scripting and Macros-Commands within scripts"></a><a name="commands"></a>Commands within scripts</h2>
 In general, a command found within a script takes the following form:<br />

<style type="text/css"><!--
/**
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 */
.text  {font-family:monospace;}
.text .imp {font-weight: bold; color: red;}
.text span.xtra { display:block; }

-->
</style><pre class="text">commandName  argument1 argument2 ...;</pre>

The commandName is a single word (token); the arguments can be multiple tokens, so long as the module knows how to interpret them. Typically each argument is a single token (though this may be string of multiple tokens converted to a single token by quotation).<br />
<h2 id="toc4"><a name="Scripting and Macros-Scripts"></a><a name="scripts"></a>Scripts</h2>
 A script consists of a series of commands. At each stage in the script, there is an implicit recipient of the command given (for instance, a module or a window). For instance, here is a script within the MESQUITE block of a NEXUS file. To the right of the commands are comments to explain them.<br />
<br />

<style type="text/css"><!--
/**
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 */
.text  {font-family:monospace;}
.text .imp {font-weight: bold; color: red;}
.text span.xtra { display:block; }

-->
</style><pre class="text">Begin MESQUITE;
  getNumberOfDataSets;      [file coordinator queried for number of data sets]
  Integer.dataSets *it;     [storing number of data sets in integer variable 'dataSets']
  getEmployee 'Data Window Coordinator'; [querying for reference to Data Window Coordinator module]
  tell It;                  [commands to follow will be sent to the Data Window Coordinator]
    Integer.dataNum 0;      [Define integer variable 'dataNum' and assign it 0]
    for *Integer.dataSets;  [for loop; cycle as many times as there are data sets]
      showDataWindow *Integer.dataNum;  [commands to make a data window for dataset]
      tell It;              [commands to follow will be sent to module that makes data window]
        showWindow;         [tells the module to make the data window visible]
      endTell;              [finished sending commands to the module that makes the data window]
      increment.dataNum;    [add 1 to the variable 'dataNum']
    endFor;                 [end of the for loop]
  endTell;                  [finished sending commands to the Data Window Coordinator]
  getNumberOfTaxas;         [file coordinator queried for number of sets of taxa]
  Integer.taxaSets *it;     [storing number of sets of taxa in integer variable 'taxaSets']
  getEmployee 'Tree Window Coordinator';  [querying for reference to Tree Window Coordinator module]
  tell It;                  [commands to follow will be sent to the Tree Window Coordinator]
    Integer.taxaNum 0;      [Define integer variable 'taxaNum' and assign it 0]
    for *Integer.taxaSets;  [for loop; cycle as many times as there are sets of taxa]
      makeTreeWindow *Integer.taxaNum;  [commands to make a tree window for set of taxa]
      tell It;              [commands to follow will be sent to module that makes tree window]
        getTreeWindow;      [queries the module to return a reference to the tree window itself]
        tell It;            [commands to follow will be sent to the tree window]
          newAssistant 'Trace Character History';  [the tree window is asked to hire a module]
        endTell;            [finished sending commands to the tree window]
        showWindow;         [tells the module to make the tree window visible]
      endTell;              [finished sending commands to the module that makes the tree window]
      increment.taxaNum;    [add 1 to the variable 'taxaNum']
    endFor;                 [end of the for loop]
  endTell;                  [finished sending commands to the Tree Window Coordinator]
END;</pre>

<br />
This MESQUITE block causes Mesquite to show a data window for each of the data sets, and a tree window for each of the Taxa blocks; the tree windows are shown with a character traced.<br />
This script illustrates some of the features of Mesquite's scripting language:<br />
<ul><li>There is a current object to which commands are sent. Which object is being commanded can be changed by a &quot;tell&quot; command. Initially, the implicit recipient of the commands is the FileCoordinator of the file in question.</li><li>Any given command may return an object that is stored within the variable referred to by &quot;It&quot;. Thus, in the above script, the makeTreeWindow returns the module hired to supervise the tree window. The immediately following command, &quot;tell It&quot; thus shifts the recipient of commands to this tree window module.</li><li>The scripting language has variables. They are defined or their values set by commands beginning, for instance, Integer.myIntegerName or Object.myObjectName. Their values can be utilized by prefixing their names by an asterisk, for instance *Integer.myIntegerName.</li><li>The scripting language has control flow, including if, for loops, and while loops.</li></ul>Some of the lines of this script are commands unique to particular commandable objects (getNumberDataSets, getEmployee, showDataWindow, etc.); others are predefined by the scripting language (e.g., Integer, tell, for). More details on particular commands can be found in the web pages linked from the &quot;Scripting Commands&quot; menu item in the Help menu when Mesquite is running. Some details are found below.<br />
<h2 id="toc5"><a name="Scripting and Macros-Variables: Integers, Strings and Objects"></a><a name="vars"></a>Variables: Integers, Strings and Objects</h2>
 Three sorts of variables are supported. Reference to each requires the type of variable with name appended, as in &quot;Integer.numberOfCharacters&quot; or &quot;Object.treeDrawCoordinator&quot;. The generic variable &quot;it&quot; refers to the object last returned by a command.<br />
When the variable is passed as an argument for a command, it should be preceeded by anasterisk. This allows the system to know that a variable, and not a constant string, is being passeed.<br />
<h3 id="toc6"><a name="Scripting and Macros-Variables: Integers, Strings and Objects-Numerical variables"></a><a name="nums"></a>Numerical variables</h3>
 Two sorts of numerical variables are supported: Integer and Number. The former contain whole numbers. The latter can contain whole or decimal numbers. Reference to each requires the type of variable with name appended, as in &quot;Integer.numberOfCharacters&quot; or &quot;Object.treeDrawCoordinator&quot;. The generic variable &quot;it&quot; refers to the object last returned by a command.<br />
When the variable is passed as an argument for a command, it should be preceeded by an asterisk. This allows the system to know that a variable, and not a constant string, is being passeed. The commands concerning variables are:<br />
<ul><li>Integer.[name] [number];— this declares an integer variable of name &quot;name&quot; and assigns it the value given by the number. If the variable already exists, its value is replaced by the number. The number may be represented by a constant, as in &quot;Integer.counter 5&quot;, by an integer variable, as in &quot;Integer.counter *Integer.previousCount&quot;, or by a String variable that contains a string that can be parsed into an integer, as in &quot;Integer.counter *String.countString&quot;. If the number is indicated as &quot;random&quot;, a random integer will be placed in the variable.</li><li>increment.[name of integer]; — this adds one to the integer's value</li><li>decrement.[name of integer]; —this subtracts one from the integer's value.</li><li>Number.[name] [number];— this declares a numerical variable of name &quot;name&quot; and assigns it the value given by the number. If the variable already exists, its value is replaced by the number. The number may be represented by a constant, as in &quot;Number.rate 0.5&quot;, by an integer variable, as in &quot;Number.rate *Number.previousRate&quot;, or by a String variable that contains a string that can be parsed into a number, as in &quot;Number.rate *String.rateString&quot;. If the number is indicated as &quot;random&quot;, a random number between 0 and 1 will be placed in the variable. If the number to be placed into the Number variable is preceeded by a '+', the number doesn't replace the existing value of the Number variable, but is added to it (similarly for '-').</li></ul><h3 id="toc7"><a name="Scripting and Macros-Variables: Integers, Strings and Objects-String variables"></a><a name="strings"></a>String variables</h3>
 One sort of variable contains a string of text. The command to define and assign values to a string variable is:<br />
<ul><li>String.[name] [string]; — this declares a String variable of name &quot;name&quot; and assigns it the value given by the string. If the variable already exists, its value is replaced by the string, unless the string passed to it is preceded by &quot;+&quot; in which case it is appended to the existing string. The string passed may be represented by a literal string, as in &quot;String.name John A. MacDonald&quot;, by an String variable, as in &quot;String.name *String.name.firstPM&quot;, or by an Object variable, in which case the name of the Object will be used.</li></ul><h3 id="toc8"><a name="Scripting and Macros-Variables: Integers, Strings and Objects-Object variables"></a><a name="objects"></a>Object variables</h3>
 One sort of variable contains a objects (such as modules, or windows). The command to define and assign values to an object variable is:<br />
<ul><li>Object.[name] [reference to object]; — this declares an Object variable and assigns it the object indicated. If the variable already exists, its value is replaced. The reference may be &quot;it&quot;, as in &quot;Object.thisModule *It&quot;, or an Object variable, as in &quot;Object.thisModule *Object.storedModule&quot;.</li></ul><h3 id="toc9"><a name="Scripting and Macros-Variables: Integers, Strings and Objects-The variable &quot;It&quot;"></a><a name="it"></a>The variable &quot;It&quot;</h3>
 Standard Mesquite Commands to modules return an object. In the scripting language, this returned object is stored in the variable &quot;It&quot;. Thus, after a command &quot;getNumberDataSets&quot; to the FileCoordinator, the FileCoordinator returns an Integer variable containing the number of data sets. This can be stored in an Integer variable by following the command by &quot;Integer.numDataSets *it&quot;. Likewise, &quot;tell&quot; often makes use of &quot;it&quot;.<br />
<br />
<h2 id="toc10"><a name="Scripting and Macros-Flow and command control"></a><a name="flowCommand"></a>Flow and command control</h2>
 As noted above Mesquite's scripting language has flow control as well as control of the object to be commanded.<br />
<h3 id="toc11"><a name="Scripting and Macros-Flow and command control-Using &quot;tell&quot; to direct commands"></a>Using &quot;tell&quot; to direct commands</h3>
 Commands are directed toward commandable objects, including modules, windows, and others. Since different objects might use the same command names, the object to which a command is directed must be indicated. In the scripting language, at any point there is an implicit object being commanded. Subsequent commands are directed to a different object using the &quot;tell&quot; command, which must be balanced by &quot;endTell&quot;. At the root level, the FileCoordinator is being commanded.<br />
<h3 id="toc12"><a name="Scripting and Macros-Flow and command control-Flow control"></a>Flow control</h3>
 Flow control statements include &quot;if&quot;, &quot;for&quot;, and &quot;while&quot;. Others are available (such as ifnot,stop, exitTell). Details on these can be found via the web page shown by selecting Scripting Commands from the Help menu while Mesquite is running.<br />
<ul><li>if [integer or integer variable]; ... endIf; — the statements between if and endIf are executed if the integer variable is non-zero</li><li>for [integer or integer variable]; ... endFor; — the statements between for and endFor are executed as many times as the initial value of the integer variable.</li><li>while [integer or integer variable]; ... endWhile; — the statements between while and endWhile are executed repeatedly as long as the value of the integer variable is non-zero.</li></ul><br />
<h2 id="toc13"><a name="Scripting and Macros-Debugging"></a><a name="debugging"></a>Debugging</h2>
 There are a number of commands that are useful for debugging. For instance, if the Command &quot;debug&quot; is placed in the block, a debugging mode will be enabled which reports in the console more details about the commands as they are executed. More information about such commands can be found by selecting the &quot;Scripting Commands&quot; menu item under the Help menu when Mesquite is running.<br />
<h2 id="toc14"><a name="Scripting and Macros-Examples"></a><a name="examples"></a>Examples</h2>
 Here are three simple example scripts that you can send to the Tree window usingWindow&gt;Scripting&gt;Send Script. Open a tree window, turn on Trace Character History, and then paste one of these scripts into the Send Script dialog box. The first script scrolls from tree to tree, for each recording in a file &quot;results.txt&quot; the reconstruction of ancestral states.<br />
<br />
<br />

<style type="text/css"><!--
/**
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 */
.text  {font-family:monospace;}
.text .imp {font-weight: bold; color: red;}
.text span.xtra { display:block; }

-->
</style><pre class="text">String.resultsFile 'results.txt';
saveMessageToFile *String.resultsFile 'RESULTS with different trees';
appendReturnToFile *String.resultsFile;
getWindow;
tell It;
    getNumTrees;
    Integer.numReps *It;
    ifNotCombinable *Integer.numReps;
        Integer.numReps 10; [in case indefinite number of trees]
    endIf;
endTell;
&nbsp;
Integer.count 0;
for *Integer.numReps;
    increment.count;
    getWindow;
    tell It;
        setTreeNumber *Integer.count;
    endTell;
    getEmployee #mesquite.ancstates.RecAncestralStates.RecAncestralStates;
    tell It;
        getLastResult;
        String.result *It;
        appendMessageToFile *String.resultsFile *String.result;
        appendReturnToFile *String.resultsFile;
    endTell;
endFor;</pre>

<br />
<br />
This second script scrolls from character to character, for each recording the ancestral states in a file &quot;results.txt&quot;:<br />
<br />
<br />

<style type="text/css"><!--
/**
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 */
.text  {font-family:monospace;}
.text .imp {font-weight: bold; color: red;}
.text span.xtra { display:block; }

-->
</style><pre class="text">String.resultsFile 'results.txt';
saveMessageToFile *String.resultsFile 'RESULTS with different characters';
appendReturnToFile *String.resultsFile;
getEmployee #mesquite.ancstates.RecAncestralStates.RecAncestralStates;
tell It;
    getNumHistories;
    Integer.numReps *It;
    ifNotCombinable *Integer.numReps;
        Integer.numReps 10; [in case indefinite number of characters]
    endIf;
endTell;
&nbsp;
Integer.count 0;
for *Integer.numReps;
    increment.count;
    getEmployee #mesquite.ancstates.TraceCharacterHistory.TraceCharacterHistory;
    tell It;
        setCharacter *Integer.count;
    endTell;
    getEmployee #mesquite.ancstates.RecAncestralStates.RecAncestralStates;
    tell It;
        getLastResult;
        String.result *It;
        appendMessageToFile *String.resultsFile *String.result;
        appendReturnToFile *String.resultsFile;
    endTell;
endFor;</pre>

<br />
<br />
The third script scrolls from tree to tree, printing each one.<br />
<br />

<style type="text/css"><!--
/**
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 */
.text  {font-family:monospace;}
.text .imp {font-weight: bold; color: red;}
.text span.xtra { display:block; }

-->
</style><pre class="text">getWindow;
tell It;
    getNumTrees;
    Integer.numReps *It;
    ifNotCombinable *Integer.numReps;
        Integer.numReps 10; [in case indefinite number of trees]
    endIf;
endTell;
for *Integer.numReps;
    getWindow;
    tell It;
        setTreeNumber *Integer.count;
        printToFit;
    endTell;
endFor;</pre>

<br />
<h2 id="toc15"><a name="Scripting and Macros-Technical Details"></a>Technical Details</h2>
 (See the <a  href="https://mesquiteproject.github.io/MesquiteDeveloperDocumentation/documentation.html" rel="nofollow">developer's documentation</a>.) The Puppeteer is in charge of defining the basic language as it relates to variables and flow control. For an object to be scriptable, it must be of the Commandable interface. Commands internally in Mesquite are remembered in objects called MesquiteCommands.
<!-- InstanceEndEditable -->

    
    
    </div>
	<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
  <div id="footer">
    <p> ©2023 Wayne P. Maddison &amp;  David R. Maddison </p>
  <!-- end #footer --></div>
<!-- end #container --></div>

<script type="text/javascript">
<!--


var OverviewOfMesquitePanel = null;
var GettingStartedPanel = null;
var BasicMesquiteOperationPanel = null;
var TaxaTreesCharactersPanel = null;
var AnalysesPanel = null;
var WorkflowsPanel = null;
var GettingHelpPanel = null;
var TechnicalDetailsPanel = null;
var HistoryPanel = null;
var PublishingResultsPanel = null;

if (qsParm['BasicMesquiteOperationPanel']=='open')
 	BasicMesquiteOperationPanel = new Spry.Widget.CollapsiblePanel("BasicMesquiteOperationPanel", {contentIsOpen: true});
else
 	BasicMesquiteOperationPanel = new Spry.Widget.CollapsiblePanel("BasicMesquiteOperationPanel", {contentIsOpen: false});
	
if (qsParm['OverviewOfMesquitePanel']=='open')
 	OverviewOfMesquitePanel = new Spry.Widget.CollapsiblePanel("OverviewOfMesquitePanel", {contentIsOpen: true});
else
 	OverviewOfMesquitePanel = new Spry.Widget.CollapsiblePanel("OverviewOfMesquitePanel", {contentIsOpen: false});
	
if (qsParm['GettingStartedPanel']=='open')
 	GettingStartedPanel = new Spry.Widget.CollapsiblePanel("GettingStartedPanel", {contentIsOpen: true});
else
 	GettingStartedPanel = new Spry.Widget.CollapsiblePanel("GettingStartedPanel", {contentIsOpen: false});

if (qsParm['TaxaTreesCharactersPanel']=='open')
 	TaxaTreesCharactersPanel = new Spry.Widget.CollapsiblePanel("TaxaTreesCharactersPanel", {contentIsOpen: true});
else
 	TaxaTreesCharactersPanel = new Spry.Widget.CollapsiblePanel("TaxaTreesCharactersPanel", {contentIsOpen: false});

if (qsParm['AnalysesPanel']=='open')
 	AnalysesPanel = new Spry.Widget.CollapsiblePanel("AnalysesPanel", {contentIsOpen: true});
else
 	AnalysesPanel = new Spry.Widget.CollapsiblePanel("AnalysesPanel", {contentIsOpen: false});

if (qsParm['WorkflowsPanel']=='open')
 	WorkflowsPanel = new Spry.Widget.CollapsiblePanel("WorkflowsPanel", {contentIsOpen: true});
else
 	WorkflowsPanel = new Spry.Widget.CollapsiblePanel("WorkflowsPanel", {contentIsOpen: false});

if (qsParm['GettingHelpPanel']=='open')
 	GettingHelpPanel = new Spry.Widget.CollapsiblePanel("GettingHelpPanel", {contentIsOpen: true});
else
 	GettingHelpPanel = new Spry.Widget.CollapsiblePanel("GettingHelpPanel", {contentIsOpen: false});
    
if (qsParm['TechnicalDetailsPanel']=='open')
 	TechnicalDetailsPanel = new Spry.Widget.CollapsiblePanel("TechnicalDetailsPanel", {contentIsOpen: true});
else
 	TechnicalDetailsPanel = new Spry.Widget.CollapsiblePanel("TechnicalDetailsPanel", {contentIsOpen: false});

if (qsParm['HistoryPanel']=='open')
 	HistoryPanel = new Spry.Widget.CollapsiblePanel("HistoryPanel", {contentIsOpen: true});
else
 	HistoryPanel = new Spry.Widget.CollapsiblePanel("HistoryPanel", {contentIsOpen: false});
if (qsParm['PublishingResultsPanel']=='open')
 	PublishingResultsPanel = new Spry.Widget.CollapsiblePanel("PublishingResultsPanel", {contentIsOpen: true});
else
 	PublishingResultsPanel = new Spry.Widget.CollapsiblePanel("PublishingResultsPanel", {contentIsOpen: false});


//-->
</script>
</body>
<!-- InstanceEnd --></html>
